package com.softline.documentsmall.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.softline.documentsmall.dao.ThumbsUpMapper;
import com.softline.documentsmall.entity.ThumbsUp;
import com.softline.documentsmall.entity.ThumbsUpVO;
import com.softline.documentsmall.service.ThumbsUpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * @program: documentsmall
 * @description:
 * @author: wmj
 * @create: 2020-12-09
 * @ClassName: ThumbsUpServiceImpl
 */
@Service
@Slf4j
public class ThumbsUpServiceImpl extends ServiceImpl<ThumbsUpMapper,ThumbsUp> implements ThumbsUpService  {

    @Autowired
    ThumbsUpMapper thumbsUpMapper;

    @Override
    public int add(ThumbsUp thumbsUp) {
        //判断此用户是否已经点赞过该词条
        QueryWrapper<ThumbsUp> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("passport_id",thumbsUp.getPassportId());
        queryWrapper.eq("dictionary_id",thumbsUp.getDictionaryId());
        ThumbsUp thumbsUp1 = this.getOne(queryWrapper);
        int result = 0;
        if (thumbsUp1 != null) {
            return result;
        }
        return thumbsUpMapper.insert(thumbsUp);
    }

    @Override
    public void delete(String passportId, Integer dictionaryId) {
            QueryWrapper<ThumbsUp> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("passport_id",passportId);
            queryWrapper.eq("dictionary_id",dictionaryId);
            this.remove(queryWrapper);
    }

    @Override
    public List<ThumbsUpVO> getReconds(String passportId, String type,Integer pageNo,Integer pageSize) {
        return thumbsUpMapper.getReconds(passportId,type,(pageNo-1)*pageSize,pageSize);
    }

    @Override
    public ThumbsUp isThumbsUp(String passportId, Integer dictionaryId) {
        QueryWrapper<ThumbsUp> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("passport_id",passportId);
        queryWrapper.eq("dictionary_id",dictionaryId);
        ThumbsUp thumbsUp = this.getOne(queryWrapper);
        return thumbsUp;
    }
}
